﻿///////////////////////////////////////////////////////////////////////////
/// File: <FileName>
/// Description: 
///    -  本文件是由代码生成工具自动生成的，如非必要，不要修改，若有新增内容，新建一个partial类进行新增。
///    -  Dao应该只能包含CRUD逻辑,所以方法命名上应该都有暗示CRUD操作的单词.方便自动生成代码与学习代码.
///    -  命名时坚持：使用CreateXXX,UpdateXXXById,UpdateXXXByConditions,DeleteXXXById,DeleteXXXsByConditions,ReadXXXById,ReadXXXsByConditions.
///    -  返回时坚持：如果单个对象没有找到,返回null,如果列表对象没有找到,返回含有零项的列表对象
///    <Description>
/// Copyright© <DateTime.Now.Year> <Copyright>
/// History:
///     <DateTime.Now>    My.GenCode    Original Version
///////////////////////////////////////////////////////////////////////////
 

using System;
using System.Collections.Generic;
using IBatisNet.DataMapper;
using IBatisNet.DataMapper.Configuration;
using MAF.Common;
using <NameSpace>.Domain.Entities;
using <NameSpace>.Domain.Interfaces;


namespace <NameSpace>.Business.Persistence
{
    public partial class <ClassName> : <InterfaceName>
    {
        protected ISqlMapper map = null;

        protected string _<CreateMethodName>SqlKey = "<EntitiesName>.<CreateMethodName>";
        protected string _<UpdateMethodName>SqlKey = "<EntitiesName>.<UpdateMethodName>";
        protected string _<DeleteMethodName>SqlKey = "<EntitiesName>.<DeleteMethodName>";
        protected string _<ReadDetailMethodName>SqlKey = "<EntitiesName>.<ReadDetailMethodName>";
        protected string _<ReadListMethodName>SqlKey = "<EntitiesName>.<ReadListMethodName>";
        protected string _<ReadCountMethodName>SqlKey = "<EntitiesName>.<ReadCountMethodName>";
        
        // 构造函数1
        public <ClassName>() : this(null){}
        // 构造函数2
        public <ClassName>( string configFile )
        {
            if( string.IsNullOrEmpty(configFile) )
            {
                //这样写，配置文件的默认文件名是--sqlmap.config
                map = Mapper.Instance(); 
            }
            else
            {
                // 这样写，配置文件为指定的文件名
                DomSqlMapBuilder sqlMapBuilder = new DomSqlMapBuilder();
                map = sqlMapBuilder.Configure(configFile);
            }
        }
        
        #region <InterfaceName>成员
        
        // Create
        public  <CreateMethodSign>
        {
            return map.Insert(_<CreateMethodName>SqlKey,info);
        }
        
        // Update
        public <UpdateMethodSign>
        {
            return map.Update(_<UpdateMethodName>SqlKey,info);
        }
        
        // Delete
        public <DeleteMethodSign>
        {
            return map.Delete(_<DeleteMethodName>SqlKey ,info);
        }
        
        // Detail，此方法传入的参数比较模糊，应该用注释加以清晰说明。
        public <ReadDetailMethodSign>
        {
            return map.QueryForObject<<EntityClassName>>(_<ReadDetailMethodName>SqlKey,info);
        }
        
        // List，此方法传入的参数比较模糊，应该用注释加以清晰说明。
        public <ReadListMethodSign>
        {
            int skip = (currentPage-1)*pageSize;
            int max = pageSize;
            return map.QueryForList<<EntityClassName>>(_<ReadListMethodName>SqlKey,info,skip,max);
        }
        
        // Count，此方法传入的参数比较模糊，应该用注释加以清晰说明。
        public <ReadCountMethodSign>
        {
            return map.QueryForObject<int>( _<ReadCountMethodName>SqlKey,info );
        }
        
        #endregion      
    }
}
    